﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


namespace Generics
{
    class MyCustomList<T> : IEnumerable where T : struct 
    {
        private T[] listCollection;
        public int Count { get; private set; }


        public int Capacity
        {
            get
            {
                return listCollection.Length;
            }
        }
        
        public T this[int index]
        {
            get
            {
                return listCollection[index];
            }
            set
            {
                listCollection[index] = value;
            }
        }

        public MyCustomList()
        {
            listCollection = new T[4];
        }

        public void Add(T value)
        {
            if (Count == listCollection.Length)
            {
                T[] newCollection = new T[Capacity*2];
                Array.Copy(listCollection, newCollection, Capacity);
                listCollection = newCollection;
            }
            listCollection[Count++] = value;
        }

        public IEnumerator GetEnumerator()
        {
            return listCollection.GetEnumerator();
        }
    }
}
